package com.example.dllo.keepdemo.person;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.dllo.keepdemo.R;
import com.example.dllo.keepdemo.base.BaseActivity;
import com.example.dllo.keepdemo.person.bean.PersonShowBean;
import com.example.dllo.keepdemo.tools.GsonRequest;
import com.example.dllo.keepdemo.tools.VolleySingleton;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by dllo on 16/1/22.
 */
public class PersonShowActivity extends BaseActivity {
    private Toolbar toolbar;
    private RecyclerView recyclerView;
    private PersonShowRecyclerViewAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personshow);
        toolbar = (Toolbar) findViewById(R.id.toolbar_activity_personshow);
        recyclerView = (RecyclerView) findViewById(R.id.recycler_activity_personshow);
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.mipmap.actionlastbtn);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PersonShowActivity.this.finish();
            }
        });
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        String id = intent.getStringExtra("id");
        String url = "https://api.gotokeep.com/v1.1/people/" + id + "/achievements/showwall";
        GsonRequest<PersonShowBean> gsonRequest = new GsonRequest<PersonShowBean>(url, PersonShowBean.class, new Response.Listener<PersonShowBean>() {
            @Override
            public void onResponse(PersonShowBean response) {
                adapter = new PersonShowRecyclerViewAdapter(PersonShowActivity.this,response);
                recyclerView.setAdapter(adapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String,String> map = new HashMap<>();
                map.put("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NjY1MDBlMTYzZGIwYzlmNTdiMTQwYWQiLCJ1c2VybmFtZSI6Iuaeq-WQmyIsImF2YXRhciI6Imh0dHA6Ly93eC5xbG9nby5jbi9tbW9wZW4vc2t3MmhSR3lXRWcwUzV0NzhkMlRVUnFhYjBzcWJ4RXB4S1BLUFpEOXpwbTNJbkIySzRjRnhLVEJsemdDb3VIcGlia3RkRUluQ0NFcGpIS2FHZ1lwRkp6SVRIVU5NYTNpYmYvMCIsImlhdCI6MTQ1MjU4OTkwNiwiZXhwIjoxNDU1MTgxOTA2LCJpc3MiOiJodHRwOi8vd3d3LmdvdG9rZWVwLmNvbS8ifQ.4I6FpbJT1_1fe8Z51oHt6Mv5t-3zXGGYhI1rMe3U8gM");
                map.put("X-X", "486bba2566a02d3ae31ed4445366a873b89cf910");
                map.put("Host", "api.gotokeep.com");
                map.put("X-KEEP-VERSION", "2.8.1");
                map.put("X-KEEP-CHANNEL", "keep");
                return map;
            }
        };
        VolleySingleton.getInstance()._addRequest(gsonRequest);
    }
}
